Skip to content

Team Example Improvements#265

Merged
ItsNature merged 2 commits intoversion/1.2.5from
improvement/optional-team-fields
Apr 9, 2026
Merged

Team Example Improvements#265
ItsNature merged 2 commits intoversion/1.2.5from
improvement/optional-team-fields

Conversation

@ItsNature
Copy link
Copy Markdown
Collaborator

@ItsNature ItsNature commented Mar 30, 2026

Overview

Description:
Updates the TeamMember object by making certain fields optional. This allows the server to include only the relevant data for each viewer, depending on context.

Changes:

  • TeamMember fields displayName, markerColor, and location are now optional
    • displayName: If not provided, only the marker is displayed.
    • markerColor: If not provided, the default color 0xFFFFFFFF is used.
    • location: The provided location is only used when the player is out of render distance for the observer. If you know that the players are close, you don't need to send the location.

Code Example (If applicable):

private TeamMember createTeamMember(Player player, boolean withinPlayerTrackingRange) {
    TeamMember.TeamMemberBuilder builder = TeamMember.builder()
        .playerUuid(player.getUniqueId())
        .markerColor(Color.WHITE);

    if (!withinPlayerTrackingRange) {
        Location location = player.getLocation();

        builder.location(ApolloLocation.builder()
            .world(location.getWorld().getName())
            .x(location.getX())
            .y(location.getY())
            .z(location.getZ())
            .build());

        builder.displayName(Component.text()
            .content(player.getName())
            .color(NamedTextColor.WHITE)
            .build());
    }

    return builder.build();
}

public void refresh() {
    for (Player viewer : this.members.values()) {
        Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
        if (!apolloPlayerOpt.isPresent()) {
            continue;
        }

        List<TeamMember> teammates = new ArrayList<>();

        for (Player member : this.members.values()) {
            if (viewer == member) {
                continue;
            }

            if (!viewer.canSee(member)) {
                continue;
            }

            if (!viewer.getWorld().getName().equals(member.getWorld().getName())) {
                continue;
            }

            boolean withinPlayerTrackingRange = this.isWithinPlayerTrackingRange(viewer, member);
            teammates.add(this.createTeamMember(member, withinPlayerTrackingRange));
        }

        apolloPlayerOpt.ifPresent(apolloPlayer -> {
            TeamApiExample.this.teamModule.updateTeamMembers(apolloPlayer, teammates);
        });
    }
}

private boolean isWithinPlayerTrackingRange(Player viewer, Player member) {
    double maxDistance = 96;
    double dx = viewer.getLocation().getX() - member.getLocation().getX();
    double dz = viewer.getLocation().getZ() - member.getLocation().getZ();

    return (dx * dx + dz * dz) <= (maxDistance * maxDistance);
}

Review Request Checklist

  • Your code follows the style guidelines of this project.
  • I have performed a self-review of my code.
  • I have tested this change myself. (If applicable)
  • I have made corresponding changes to the documentation. (If applicable)
  • The branch name follows the projects naming conventions. (e.g. feature/add-module & bugfix/fix-issue)

@ItsNature ItsNature added type: Documentation Documentation improvement or issue type: Enhancement Feature improvement or addition labels Mar 30, 2026
@ItsNature ItsNature mentioned this pull request Apr 1, 2026
@ItsNature ItsNature merged commit 59f7609 into version/1.2.5 Apr 9, 2026
2 checks passed
@ItsNature ItsNature deleted the improvement/optional-team-fields branch April 9, 2026 21:47
ItsNature added a commit that referenced this pull request Apr 17, 2026
* Deploy as 1.2.5-SNAPSHOT

* Lightweight(JSON): Add serverbound & roundtrip packets examples (#264)

* lightweight(json): add serverbound & roundtrip packets examples

* change wording

* change wording

---------

Co-authored-by: Trentin <25537885+TrentinTheKid@users.noreply.github.com>

* Update license year (#266)

* Team Example Improvements (#265)

* Better team example: filter hidden players, send location & display name only if outside player view distance

* example(team): update default max distance

* Implement CooldownStyle (#267)

* Feature - Server Links (#261)

* Add base ServerLinkModule

# Conflicts:
#	docs/developers/lightweight/protobuf/getting-started.mdx
#	gradle/libs.versions.toml

* server links api (WIP)

* add the json & proto examples

* add markdown docs

* update serverlink docs

* update paths in notification module example

* update server link overview img

* update overview desc

* update component usage docs

* Update version tags to 1.2.5

* Update license year

* Fix conflicts

* Remove extra line

---------

Co-authored-by: TrentinTheKid <25537885+TrentinTheKid@users.noreply.github.com>

* Implement `ModSettingsModule#requestInstalledMods` (#269)

* Sync LunarClient Mods & Options (#270)

* Sync LunarClient Mods & Options

* Update version tags to 1.2.5

---------

Co-authored-by: LunarClient Bot <lc-bot@moonsworth.com>

* Bump to 1.2.5 (#271)

---------

Co-authored-by: Trentin <25537885+TrentinTheKid@users.noreply.github.com>
Co-authored-by: LunarClient Bot <lc-bot@moonsworth.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: Documentation Documentation improvement or issue type: Enhancement Feature improvement or addition

Development

Successfully merging this pull request may close these issues.

3 participants